package com.citcc.business.service;

import com.citcc.business.bean.Monitor;
import com.citcc.business.mapper.MonitorCenterMapper;
import com.citcc.common.utils.http.HttpUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class MonitorCenterService {

    private final MonitorCenterMapper monitorCenterMapper;

    @Autowired
    public MonitorCenterService(MonitorCenterMapper monitorCenterMapper){
        this.monitorCenterMapper=monitorCenterMapper;
    }

    /**
     * 获取orgId下的所有子机构
     *
     * @param orgId
     * @return
     */
    public List<Map<String, String>> getOrgTree(String orgId) {
        return monitorCenterMapper.getOrgTree(orgId);
    }
    /**
     * 获取orgId下的所有充电站信息
     *
     * @param orgId
     * @return
     */
    public List<Map<String, String>> getStationList(@Param("orgId") String orgId){
        return monitorCenterMapper.getStationList(orgId);
    }

    public Map<String,String> getGDInfoById(String id){
        return monitorCenterMapper.getGDInfoById(id);
    }

    public List<Monitor> queryByList(Monitor mo){
        List<Monitor> list=monitorCenterMapper.queryByList(mo);
        if(list!=null){
            for(int i=0;i<list.size();i++){
                if(list.get(i).getChargeState().equals("2")){
                    list.get(i).setStartTime(list.get(i).getEndTime());
                    list.get(i).setChargeDl(null);
                    list.get(i).setChargeType(null);
                    list.get(i).setChargeMs(null);
                    list.get(i).setChargeDn(null);
                    list.get(i).setChargeDy(null);
                    list.get(i).setSoc(null);
                    list.get(i).setChargeLong(null);
                    list.get(i).setSyTime(null);
                    list.get(i).setEndType(null);
                    list.get(i).setUserPhone(null);
                }
            }
        }
        return list;
    }

    /**
     * 获得站点的数量
     */
    public Map<String,String> getAllCount(String stationId,String type){
        Map<String, String> map = new HashMap<>();
        //获得站点的直流和交流数量
        //获取某站点的空闲枪数量
        int gunCount=monitorCenterMapper.gunCount(stationId,type);
        //根据站点ID查询总的枪数量
        int stakeCount=monitorCenterMapper.stakeCount(stationId,type);
        int online=stakeCount-gunCount;
        map.put("stakeCount",String.valueOf(stakeCount));
        map.put("gunCount",String.valueOf(gunCount));
        map.put("online",String.valueOf(online));
        return map;
    }

}
